/**
 * @table: ${table.tableName}
 * @author : ${parametersConfig.author}
 * @date: ${date}
 * Code Generate By RateCode
 * Code Generate Gitee : https://gitee.com/GaopanL/rateCode
 */

package ${parametersConfig.packPath}.${module};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.cglib.beans.BeanMap;
import java.util.List;
import java.util.Map;
import me.gopal.message.QueryByPageResponse;
import me.gopal.message.QueryResponse;
import ${parametersConfig.packPath}.entity.${table.tableNameConverted};
import ${parametersConfig.packPath}.repository.${table.tableNameConverted}Repository;

@Service
public class ${table.tableNameConverted}Service implements ${table.tableNameConverted}Api{

    @Autowired
    private ${table.tableNameConverted}Repository ${table.tableNameHump}Repository;

    public void insert(${table.tableNameConverted} ${table.tableNameHump}){
        ${table.tableNameHump}Repository.insert(${table.tableNameHump});
    }

    public QueryByPageResponse queryByPage(${table.tableNameConverted} ${table.tableNameHump}){
        Map<String,Object> map = BeanMap.create(${table.tableNameHump});
        List<${table.tableNameConverted}> list = ${table.tableNameHump}Repository.queryByPage(map);
        long rows = ${table.tableNameHump}Repository.getTotal(map);
        return QueryByPageResponse.builder()
            .data(list).rows(rows)
            .build();
    }

    public QueryResponse queryById(long id){
        ${table.tableNameConverted} ${table.tableNameHump} = ${table.tableNameHump}Repository.getById(id);
        return QueryResponse.builder().data(${table.tableNameHump}).build();
    }

    public void update(${table.tableNameConverted} ${table.tableNameHump}){
        ${table.tableNameHump}Repository.update(${table.tableNameHump});
    }

    public void deleteById(long id){
        ${table.tableNameHump}Repository.deleteById(id);
    }

}